package Thread;

public class ThreadDemo13 {
    public static void main(String[] args) {
        Thread thread = new Thread(() ->{
            //Thread.currentThread()    获取当前线程实例，也就是thread
            while(!Thread.currentThread().isInterrupted()){//前提是要有当前标志
                System.out.println("我是一个线程，工作中");
                try {//如果在sleep的过程中调用interrupt大概在休眠时间没到的时候就被唤醒了
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                   break;
                }
            }
            System.out.println("线程执行完毕");
        });

        thread.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //使用interup方法，修改刚才标志位的值
        System.out.println("让thread线程结束");
        thread.interrupt();//相当于isQuit = true

    }
}
